﻿/****************************** Module Header ******************************\
 * Module Name:  mxButton.cs
 * Module Version:  1.0.0 (2012-8-8)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This class is used for mxButton. 
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System;
using System.Drawing;
using System.Windows.Forms;

namespace UCL.Forms
{
    public static class mxButton
    {        
        /// <summary>
        /// 按钮上鼠标 移入、移出、按下、弹起背景图片
        /// </summary>
        /// <param name="btn"></param>
        /// <param name="bgNormal"></param>
        /// <param name="bgMove"></param>
        /// <param name="bgClick"></param>
        public static void SetBackgroundImage(this Button btn, Image bgNormal, Image bgMove, Image bgClick=null)
        {
            btn.BackgroundImage = bgNormal;
            btn.MouseEnter += delegate(object sender, EventArgs e) { ((Button)sender).BackgroundImage = bgMove; };
            btn.MouseLeave += delegate(object sender, EventArgs e) { ((Button)sender).BackgroundImage = bgNormal; };
            if (bgClick != null) btn.MouseDown += delegate(object sender, MouseEventArgs e) { ((Button)sender).BackgroundImage = bgClick; };
            btn.MouseUp += delegate(object sender, MouseEventArgs e) { ((Button)sender).BackgroundImage = bgNormal; };
        }
    }
}
